package com.sgb.kjwl.view.ui.adapter.transport;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.utils.DefaultUtil;
import com.swgk.core.customview.SeeMoreView;
import com.swgk.core.util.StringUtil;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 3/3/21 4:47 PM
 * @Description: 接单页展示列表适配器
 */
public class PayGoodsInfoAdapter extends BaseMultiItemQuickAdapter<SingleItemEntity, BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public PayGoodsInfoAdapter(List<SingleItemEntity> data) {
        super(data);
        //正常展示
        addItemType(SingleItemConstant.TYPE_ONE, R.layout.item_cargo_orders_one);
        //金额展示
        addItemType(SingleItemConstant.TYPE_TWO, R.layout.item_cargo_orders_two);
        //电话展示
        addItemType(SingleItemConstant.TYPE_THREE, R.layout.item_cargo_orders_three);
        //分割线
        addItemType(SingleItemConstant.TYPE_FOUR, R.layout.item_cargo_orders_four);
    }

    @Override
    protected void convert(BaseViewHolder helper, SingleItemEntity item) {
        switch (item.getItemType()) {
            case SingleItemConstant.TYPE_ONE:
                initNormal(helper, item);
                break;
            case SingleItemConstant.TYPE_TWO:
                initPrice(helper, item);
                break;
            case SingleItemConstant.TYPE_THREE:
                initPhone(helper, item);
                break;
            case SingleItemConstant.TYPE_FOUR:
                break;
        }
    }

    private void initNormal(BaseViewHolder helper, SingleItemEntity item) {
        helper.setText(R.id.tv_item_title, item.getLeftString());
        //设置内容
        SeeMoreView moreView = helper.getView(R.id.tv_item_content);
        moreView.setText(DefaultUtil.getString(item.getRightString()));
    }

    private void initPrice(BaseViewHolder helper, SingleItemEntity item) {
        helper.setText(R.id.tv_item_title, item.getLeftString())
                .setText(R.id.tv_item_content, item.getRightString());
    }

    private void initPhone(BaseViewHolder helper, SingleItemEntity item) {
        String end = "（接单后于运输订单中可见）";
        String content = String.format("%s%s", StringUtil.gonePhone(item.getRightString()), end);
        SpannableString spannableString = new SpannableString(content);
        spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#969696"))
                , content.indexOf(end), content.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        helper.setText(R.id.tv_item_title, item.getLeftString())
                .setText(R.id.tv_item_content, spannableString);
    }
}
